Docker Containers
What is a docker Container
As said in the previous article, A docker container looks at the docker image and runs an instance of it.
Docker Containers are just runtime instances that are made to be deleted and created seamlessly, This is very useful for scaling where new instances can be created and destroyed as per required load.
Key Characteristics of a Docker Container:
-
Isolated (sandboxed): Containers are isolated from the host system and other containers. They have their own filesystem, processes, and network stack.
-
Lightweight: Containers share the host operating system’s kernel, making them more efficient and faster to start than virtual machines.
-
Ephemeral: Containers are often designed to be stateless and temporary. Data stored inside a container is lost when it stops unless it's kept in a volume.
How it Works:
-
Image: A container is created from an image, the image is like it's blueprint
-
Execution Environment: The container includes the runtime environment, dependencies and other binaries required to run the code inside
-
Sandboxed: Containers run in isolation but can communicate with each other through networks if configured.
-
Persistent Storage (Optional): Containers can be connected to volumes to persist data Even after they're deleted, although typically they aren't
Lifecycle of a Docker Container:
-
Creation: The container is created from an image with the environment ready to run.
-
Run: The container starts running the code.
-
Stop (pause): The container stops running it but it still exists (could say in a FREEZE state, data isn't lost if it's not connected to a volume).
-
Delete: The container can be removed when no longer needed.
Additionally, Ports active inside a container are isolated from the outside world (your computer), so to access them you must port-forward.